package com.ymkj.testdemo.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallableTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallable myCallable = new MyCallable();
        //MyCallable myCallable2 = new MyCallable();
        //MyCallable myCallable3 = new MyCallable();
        FutureTask futureTask = new FutureTask<>(myCallable);
        FutureTask futureTask2 = new FutureTask<>(myCallable);
        FutureTask futureTask3 = new FutureTask<>(myCallable);
        Thread t1 = new Thread(futureTask);
        Thread t2 = new Thread(futureTask);
        Thread t3 = new Thread(futureTask);
        t1.start();
        t2.start();
        t3.start();
        System.out.println(futureTask.get());
        //System.out.println(futureTask2.get());
        //System.out.println(futureTask3.get());


    }

}

class MyCallable implements Callable{

    private static int tiketNum = 20;

    @Override
    public Object call() throws Exception {
        while (tiketNum > 0){
            System.out.println(Thread.currentThread().getName() +"卖出第" + tiketNum +"张票");
            tiketNum--;
            //Thread.sleep(1000);
        }
        return "卖完了！";
    }
}